package com.example.demo.mapper;

import com.example.demo.entity.AfoneCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 分类内容 Mapper 接口
 * </p>
 *
 * @author Mr.Xiayh
 * @since 2024-06-17
 */
@Mapper
public interface AfoneCategoryMapper extends BaseMapper<AfoneCategory> {
    /**
     * 根据ID查询AfoneCategory对象。
     *
     * @param id 分类的唯一标识符。
     * @return 返回匹配ID的AfoneCategory对象，如果找不到，则返回null。
     */
    @Select("select * from afone_category where id = #{value}")
    AfoneCategory queryObject(@Param("value")Integer id);

    /**
     * 根据条件查询AfoneCategory对象列表。
     *
     * @param map 包含查询条件的键值对，键是条件字段名，值是条件值。
     * @return 返回匹配条件的AfoneCategory对象列表，如果找不到匹配项，则返回空列表。
     */
    @Select("<script>" +
            "select" +
            "        <if test='fields != null and fields != \"\"'>" +
            "            ${fields}" +
            "        </if>" +
            "        <if test='fields == null or fields == \"\"'>" +
            "            *" +
            "        </if>" +
            "        from afone_category" +
            "        where 1 = 1" +
            "        <if test='parentId != null and parentId != null'>" +
            "            and parent_id = #{parentId}" +
            "        </if>" +
            "        <if test='notName != null and notName != null'>" +
            "            and 'name' != #{notName}" +
            "        </if>" +
            "        <if test='ids != null'>" +
            "            and id in" +
            "            <foreach item='item' collection='ids' open='(' separator=',' close=')'>" +
            "                #{item}" +
            "            </foreach>" +
            "        </if>" +
            "        <choose>" +
            "            <when test='sidx != null and sidx.trim() != \"\"'>" +
            "                order by ${sidx} ${order}" +
            "            </when>" +
            "            <otherwise>" +
            "                order by id asc" +
            "            </otherwise>" +
            "        </choose>" +
            "        <if test='offset != null and limit != null'>" +
            "            limit #{offset}, #{limit}" +
            "        </if>" +
            "</script>")
    List<AfoneCategory> queryList(Map<String, Object> map);

    /**
     * 根据条件查询AfoneCategory对象的总数。
     *
     * @param map 包含查询条件的键值对，键是条件字段名，值是条件值。
     * @return 返回满足条件的AfoneCategory对象总数。
     */
    @Select("select count(*) from afone_category")
    int queryTotal(Map<String, Object> map);
}
